home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1649 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.magi.com!news!news.magi.com
  2. From: nredding@magi.com (Neil Redding)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What the hell is THIS?!
  5. Date: Mon, 15 Jan 1996 16:26:36 -0500
  6. Organization: Magi Data Consulting
  7. Message-ID: <nredding-1501961626360001@magi03p10.magi.com>
  8. References: <4d6rgh$rfu@abel.cc.sunysb.edu> <coc-1301960253420001@dal1498.computek.net>
  9. NNTP-Posting-Host: magi03p10.magi.com
  10.  
  11. In article <coc-1301960253420001@dal1498.computek.net>, coc@computek.net
  12. (Chad Cranfill) wrote:
  13.  
  14. >In article <4d6rgh$rfu@abel.cc.sunysb.edu>, bmadhusu@engws12.ic.sunysb.edu
  15. >(Bommasamudram Madhusudan) wrote:
  16. >
  17. >> Can someone explain what
  18. >> 
  19. >>   int (*p)[3]  is?????
  20. >> 
  21. >
  22. >Starting with the "p", we parse the expression thusly: "p is an array of 3
  23. >pointers to int". If you need help with this (believe me, I did!) get the
  24. >book "Deep C Secrets". It presents an algorithmic method for decoding
  25. >statements like this, and gives hints on how to implement a C program that
  26. >will do this for you.
  27.  
  28. I think you need to reread "Deep C Secrets". The above is actually "a
  29. pointer to array[3]
  30. of ints".  This actual example is in K & R, Section 5.12,  if you want to check.
  31.  
  32. int *p[3] ( == *(p[3]) ) is "an array of 3 pointers to int".
  33. >
  34. >> 
  35. >> I can say things like:
  36. >> 
  37. >> (*p)[0] = 3; for e.g, but when I print the value using:
  38. >> 
  39. >>  printf("%d",(*p)[0]) I get a core dump!
  40. >
  41. It would be necessary to see the rest of the program to determine why it crashed
  42. at the printf.  If p was a null pointer then (*p)[0]=3 could work but the printf
  43. statement would crash. See also "Deep C Secrets", Chapter 10.
  44.  
  45. -- 
  46. Neil Redding
  47. Ottawa, Canada
  48.